package com.song.sample.controller;

import com.song.sample.config.pagination.Page;
import com.song.sample.config.pagination.PageRequestParam;
import com.song.sample.entity.User;
import com.song.sample.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * @desc: user控制类
 * @author: WUSONG
 * @date: 2018/6/25 0025 下午 2:58
 */
@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;


    @RequestMapping(value = "users", method = RequestMethod.GET)
    @ResponseBody
    public Page<User> queryAllUsers(User uservo, PageRequestParam pageRequestParam){
        Pageable pageable = pageRequestParam.build();
        return userService.queryUsers(uservo, pageable);
    }


    @RequestMapping(value = "users/{userId}", method = RequestMethod.GET)
    @ResponseBody
    public User getUserByUserId(@PathVariable(value = "userId") Long userId){
        return userService.getUserById(userId);
    }

    @RequestMapping(value = "toUserPage", method = RequestMethod.GET)
    public String toUserPage(Map<String, Object> model){
        User user = new User();
        user.setUserId(1L);
        user.setUserName("admin");
        model.put("user", user);
        return "user/user";
    }


}
